﻿using System;
using System.Web.UI;
using Emz.Core.Models;
using Legazpi.Payroll.Services.Interfaces;
using Ninject;
using Legazpi.Payroll.Web.Helpers;

namespace Legazpi.Payroll.Web.PopupBoxes
{
    public partial class SectorDialogBox : System.Web.UI.Page
    {
        [Inject]
        public IPositionService _positionService { get; set; }
        [Inject]
        public ISectorService _sectorService { get; set; }

        protected Sector Model { get; private set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                int id;
                int.TryParse(Request.QueryString["id"], out id);
                if (id > 0)
                    //Update Data
                    Model = _sectorService.GetById(id);
            }
            //New Data
            int clientId;
            int.TryParse(Request.QueryString["cid"], out clientId);

            Model = Model ?? new Sector { Id = 0 , ClientId = clientId};

            if (!Page.IsPostBack)
                BindDropdowns();
        }

        #region Implementations
        void BindDropdowns()
        {
            //Positions                                              
            PositionDropdown.ToPositionSelectList(Model.PositionId);
        }
        #endregion
    }
}